package com.linghang.demo.controller;

import com.linghang.demo.domain.Production;
import com.linghang.demo.req.ProductionQueryReq;
import com.linghang.demo.req.ProductionSaveReq;
import com.linghang.demo.resp.CommonResp;
import com.linghang.demo.resp.ProductionQueryResp;
import com.linghang.demo.resp.PageResp;
import com.linghang.demo.service.ProductionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

//作品
@RestController
@RequestMapping ("/production")
public class ProductionController {


    @Resource
    private ProductionService productionService;


    @GetMapping("/list1")
    public CommonResp list() {
        CommonResp<List<Production>> resp = new CommonResp<>();
        List<Production> list = productionService.list();
        resp.setContent(list);
        return resp;
    }
    @GetMapping("/list")
    public CommonResp list(@Valid ProductionQueryReq req) {
        CommonResp<PageResp<ProductionQueryResp>> resp = new CommonResp<>();
        PageResp<ProductionQueryResp> list = productionService.list(req);
        resp.setContent(list);
        return resp;
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable int id){
        CommonResp resp=new CommonResp<>();
        productionService.delete(id);

        return resp;
    }

    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody ProductionSaveReq req) {
        CommonResp resp = new CommonResp<>();
        productionService.save(req);
        return resp;
    }
}